package com.zxc.controller.admin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zxc.model.*;
import com.zxc.model.Diseases.DiseasesDetails;
import com.zxc.model.Equipment.Equipment;
import com.zxc.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@CrossOrigin
@ResponseBody
@RequestMapping("/admin")
public class adminController {
    @Autowired
    private AdminService adminService;

    //插入植物数据信息
    @RequestMapping("/insertPlantInfo")
    public ResponseEntity<?> insertPlantInfo(@RequestBody Plant plant) {
        return ResponseEntity.ok(adminService.insertPlantInfo(plant));
    }

    //插入病症信息
    @RequestMapping("/insertDiseasesInfo")
    public ResponseEntity<?> insertDiseasesInfo(@RequestBody DiseasesDetails diseasesDetails) {
        return ResponseEntity.ok(adminService.insertDiseasesInfo(diseasesDetails));
    }
    //插入肥料信息数据
    @RequestMapping("/insertFertilizerData")
    public ResponseEntity<?> insertFertilizerData(@RequestBody Fertilizer fertilizer) {
        return ResponseEntity.ok(adminService.insertFertilizerData(fertilizer));
    }

    //插入农药信息数据
    @RequestMapping("/insertPesticideData")
    public ResponseEntity<?> insertPesticideData(@RequestBody Pesticide pesticide) {
        return ResponseEntity.ok(adminService.insertPesticideData(pesticide));
    }
    //插入设备仓库信息数据
    @RequestMapping("/insertEquipmentWarehouseData")
    public ResponseEntity<?> insertEquipmentWarehouseData(@RequestBody Equipment equipment) {
        return ResponseEntity.ok(adminService.insertEquipmentWarehouseData(equipment));
    }

    //插入肥料仓库信息数据
    @RequestMapping("/insertFertilizerWarehouseData")
    public ResponseEntity<?> insertFertilizerWarehouseData(@RequestBody Fertilizer fertilizer) {
        return ResponseEntity.ok(adminService.insertFertilizerWarehouseData(fertilizer));
    }

    //插入农药仓库信息数据
        @RequestMapping("/insertPesticideWarehouseData")
    public ResponseEntity<?> insertPesticideWarehouseData(@RequestBody Pesticide pesticide) {
        return ResponseEntity.ok(adminService.insertPesticideWarehouseData(pesticide));
    }

    //插入种子仓库信息数据
    @RequestMapping("/insertSeedWarehouseData")
    public ResponseEntity<?> insertSeedWarehouseData(@RequestBody seeds seeds) {
        return ResponseEntity.ok(adminService.insertSeedWarehouseData(seeds));
    }

    //插入农具仓库信息数据
    @RequestMapping("/insertToolsWarehouseData")
    public ResponseEntity<?> insertToolsWarehouseData(@RequestBody Tools vo) {
        return ResponseEntity.ok(adminService.insertToolsWarehouseData(vo));
    }
//修改
//插入肥料仓库信息数据
@RequestMapping("/updateFertilizerWarehouseData")
public ResponseEntity<?> updateFertilizerWarehouseData(@RequestBody Fertilizer fertilizer) {
    return ResponseEntity.ok(adminService.updateFertilizerWarehouseData(fertilizer));
}

    //插入农药仓库信息数据
    @RequestMapping("/updatePesticideWarehouseData")
    public ResponseEntity<?> updatePesticideWarehouseData(@RequestBody Pesticide pesticide) {
        return ResponseEntity.ok(adminService.updatePesticideWarehouseData(pesticide));
    }

    //插入种子仓库信息数据
    @RequestMapping("/updateSeedWarehouseData")
    public ResponseEntity<?> updateSeedWarehouseData(@RequestBody seeds seeds) {
        return ResponseEntity.ok(adminService.updateSeedWarehouseData(seeds));
    }

    //插入农具仓库信息数据
    @RequestMapping("/updateToolsWarehouseData")
    public ResponseEntity<?> updateToolsWarehouseData(@RequestBody Tools vo) {
        return ResponseEntity.ok(adminService.updateToolsWarehouseData(vo));
    }
//    修改

    //查询农药信息
    @RequestMapping("/getPesticideDate")
    public ResponseEntity<?> getPesticideDate(@RequestBody Pesticide pesticide) {
        Page page =pesticide.getPageList().get(0);
        PageHelper.offsetPage(page.getOffset(), page.getLimit());
        return ResponseEntity.ok(new PageInfo<Pesticide>(adminService.getPesticideDate(pesticide)));
    }
    //查询植物信息
    @RequestMapping("/getPlantDate")
    public ResponseEntity<?> getPlantDate(@RequestBody Plant plant) {
        Map<String, Object> response = new HashMap<String, Object>();
        Page page =plant.getPageList().get(0);
        PageHelper.offsetPage(page.getOffset(), page.getLimit());
        response.put("PlantList",new PageInfo<Plant>(adminService.getPlantDate(plant)));
        return ResponseEntity.ok(response);
    }
    //查询肥料信息
    @RequestMapping("/getFertilizerDate")
    public ResponseEntity<?> getFertilizerDate(@RequestBody Fertilizer fertilizer) {
        Page page =fertilizer.getPageList().get(0);
        PageHelper.offsetPage(page.getOffset(), page.getLimit());
        return ResponseEntity.ok(new PageInfo<Fertilizer>(adminService.getFertilizerDate(fertilizer)));
    }

    //查询农具信息
    @RequestMapping("/getToolsDate")
    public ResponseEntity<?> getToolsDate(@RequestBody Tools tools) {
        Page page =tools.getPageList().get(0);
        PageHelper.offsetPage(page.getOffset(), page.getLimit());
        return ResponseEntity.ok(new PageInfo<Tools>(adminService.getToolsDate(tools)));
    }


}
